﻿﻿@model IEnumerable<SIG.Model.Identity.Role>

@{
    var modelName = SettingsManager.Role.ModelName;
    ViewBag.PageTitle = modelName;
    ViewBag.Title = ViewBag.PageTitle + "_安全";
}

@section leftNav{
    @Html.Partial("_NavForSecurity")
}

<div class="main-content">
    <div class="panel panel-default">
        <header class="panel-heading">
            <h3 class="panel-title">
                <span class="@SettingsManager.Role.IconClass"></span> @ViewBag.PageTitle
            </h3>
        </header>
        <div class="panel-body text-right">
            <a href="@Url.Action("Create")" class="btn btn-primary"><span class="glyphicon glyphicon-pencil"></span> 新建角色</a>
        </div>
        <table class="table table-striped table-bordered" id="list">
            <thead>
                <tr>
                    <th>
                        @Html.DisplayNameFor(model => model.RoleName)
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.Description)
                    </th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in Model)
                {
                    <tr>
                        <td>
                            @Html.DisplayFor(modelItem => item.RoleName)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.Description)
                        </td>
                        <td>
                            @*<a href="@Url.Action("Edit", new { id = item.Id })" class="btn btn-xs btn-primary" data-toggle="tooltip" data-placement="top" title="编辑"><i class="glyphicon glyphicon-edit"></i></a>*@
                            <a href="@Url.Action("Delete", new { id = item.Id })" data-confirm="你确定要删除 @item.RoleName 吗？" class="btn btn-xs btn-danger delete-item" data-toggle="tooltip" data-placement="top" title="删除"><i class="glyphicon glyphicon-trash"></i></a>

                        </td>
                    </tr>
                }
            </tbody>
        </table>
    </div>
</div>


@section Footer{

    <script src="~/Scripts/bootbox.js"></script>
    <script>

        $(function () {
            //当前链接;
            Common.ActiveCurrentNav();

            var modelName = "@modelName";

            //确认框默认语言
            bootbox.setDefaults({
                locale: "zh_CN"
            });

            //删除数据
            $('.delete-item').click(function (e) {
                e.preventDefault();
                var url = $(this).attr('href');
                var confireMes = $(this).attr('data-confirm');
                var that = $(this);


                bootbox.confirm(confireMes, function (result) {
                    if (result) {
                        /*DELETE*/
                        $.ajax({
                            url: url,
                            dataType: "json",
                            type: "POST",
                            contentType: 'application/json; charset=utf-8',
                            data: JSON.stringify({}),
                            async: true,
                            processData: false,
                            cache: false,
                            success: function (result) {
                                if (result) {
                                    toastr.success(modelName + '已删除成功！', '删除' + modelName);
                                    that.closest('tr').remove();
                                } else {
                                    toastr.error(modelName + '删除失败！', '删除' + modelName);
                                }
                            },
                            error: function (xhr) {
                                toastr.error(modelName + '删除失败！', '删除' + modelName);
                            }
                        });
                    }

                });

            })

        });
    </script>

}